package com.ktjy.crm.controller;

import com.ktjy.crm.entity.SysUser;
import com.ktjy.crm.service.SysUserservice;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.Date;
import java.util.List;

/**
 * @Description
 * @Author 曹正
 * @Date 2025/1/6 19:51
 **/
@Controller
public class ExamplController {
    @Resource
    private SysUserservice sysUserservice;

    @GetMapping(value = "/hello/{id}")
    public String getUser(@PathVariable("id") int id, Model model){
        SysUser sysUser=sysUserservice.getUser(id);
        model.addAttribute("user",sysUser);
        return "demo/hello";
    }

    @GetMapping(value = "string")
    public String getString(Model model, HttpServletRequest request){
        model.addAttribute("userName","ktjiaoyu");
        request.setAttribute("test","request");
        request.getSession().setAttribute("test","session");
        model.addAttribute("date",new Date());
        return "demo/string";
    }

    @GetMapping(value = "/inline")
    public String getInline(Model model){
        model.addAttribute("userName","ktjiaoyu");
        return "demo/inline";
    }

    @GetMapping(value = "/if")
    public String ifunless(Model model){
        model.addAttribute("flag","yes");
        return "demo/if";
    }

    @GetMapping(value = "/list")
    public String list(Model model){
        List<SysUser> list=sysUserservice.findAllUsers();
        model.addAttribute("users",list);
        return "demo/list";
    }
}
